export const months = [
    {
        label: "1月",
        value: "1"
    },
    {
        label: "2月",
        value: "2"
    },
    {
        label: "3月",
        value: "3"
    },
    {
        label: "4月",
        value: "4"
    },
    {
        label: "5月",
        value: "5"
    },
    {
        label: "6月",
        value: "6"
    },
    {
        label: "7月",
        value: "7"
    },
    {
        label: "8月",
        value: "8"
    },
    {
        label: "9月",
        value: "9"
    },
    {
        label: "10月",
        value: "10"
    },
    {
        label: "11月",
        value: "11"
    },
    {
        label: "12月",
        value: "12"
    }
];

//根据季度生成月份
export function getMonths (quarter) {
    let arr = [];
    for (let i = 0; i < 3; i++) {
        arr.push(months[i + (quarter - 1) * 3]);
    }
    return arr;
}

export const quarters = [
    {
        label: "一季度",
        value: "1"
    },
    {
        label: "二季度",
        value: "2"
    },
    {
        label: "三季度",
        value: "3"
    },
    {
        label: "四季度",
        value: "4"
    }
];

function generateRandomString (length) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    const charactersLength = characters.length;
    for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * charactersLength);
        result += characters[randomIndex];
    }
    return result;
}

export const carouselList = [
    [
        {
            name: "磷酸一铵",
            value: 78,
            id: generateRandomString(4)
        },
        {
            name: "磷酸二铵",
            value: 20,
            id: generateRandomString(4)
        },
        {
            name: "磷酸三铵",
            value: 30,
            id: generateRandomString(4)
        },
        {
            name: "磷酸四铵",
            value: 40,
            id: generateRandomString(4)
        }
    ],
    [
        {
            name: "电池一铵",
            value: 95,
            id: generateRandomString(4)
        },
        {
            name: "电池二铵",
            value: 20,
            id: generateRandomString(4)
        },
        {
            name: "电池三铵",
            value: 30,
            id: generateRandomString(4)
        },
        {
            name: "电池四铵",
            value: 40,
            id: generateRandomString(4)
        }
    ],
    [
        {
            name: "晶体一铵",
            value: 46,
            id: generateRandomString(4)
        },
        {
            name: "晶体二铵",
            value: 20,
            id: generateRandomString(4)
        },
        {
            name: "晶体三铵",
            value: 30,
            id: generateRandomString(4)
        },
        {
            name: "晶体四铵",
            value: 40,
            id: generateRandomString(4)
        }
    ]
];
export const comList = [
    [
        {
            name: "磷酸一铵",
            value: 58
        },
        {
            name: "磷酸二铵",
            value: 20
        },
        {
            name: "磷酸三铵",
            value: 30
        },
        {
            name: "磷酸四铵",
            value: 40
        },
        {
            name: "磷酸五铵",
            value: 40
        },
        {
            name: "磷酸六铵",
            value: 40
        },
        {
            name: "磷酸七铵",
            value: 40
        },
        {
            name: "磷酸八铵",
            value: 40
        },
        {
            name: "磷酸九铵",
            value: 40
        }
    ],
    [
        {
            name: "电池一铵",
            value: 95
        },
        {
            name: "电池二铵",
            value: 20
        },
        {
            name: "电池三铵",
            value: 30
        },
        {
            name: "电池四铵",
            value: 40
        }
    ]
];

/**
 *
 * @param count 环形占比
 * @param width
 * @param height
 */
export function computedXY (count, width, height) {
    const centerX = width / 2;
    const centerY = height / 2;
    const d = count * 360 / 100;
    const circleCenter = {
        name: "时间",
        x: centerX,
        y: centerY
    }
    let markLineData = []
    let labelPosition = "start"
    if (count > 0 && count < 25) {
        markLineData = [
            [
                {
                    x: centerX + Math.tan(d * Math.PI / 180) * centerX,
                    y: 0
                },
                circleCenter,
            ]
        ]
        labelPosition = "end"
    } else if (count === 25) {
        markLineData = [
            [
                circleCenter,
                {
                    x: width,
                    y: centerY
                }
            ]
        ]
    } else if (count > 25 && count < 50) {
        markLineData = [
            [
                circleCenter,
                {
                    x: centerX + (Math.tan((90 - (d - 90)) * Math.PI / 180) * centerX),
                    y: height
                }
            ],
        ]
    } else if (count === 50) {
        markLineData = [
            [
                circleCenter,
                {
                    x: centerX,
                    y: height
                }
            ]
        ]
    } else if (count > 50 && count < 75) {
        markLineData = [
            [
                circleCenter,
                {
                    x: centerX - Math.tan((d - 180) * Math.PI / 180) * centerX,
                    y: height
                }
            ]
        ]
    } else if (count === 75) {
        markLineData = [
            [
                circleCenter,
                {
                    x: 0,
                    y: centerY
                }
            ]
        ]
    } else if (count > 75 && count < 100) {
        markLineData = [
            [
                circleCenter,
                {
                    x: 0,
                    y: centerY - Math.tan((d - 270) * Math.PI / 180) * centerX,
                }
            ]
        ]
        labelPosition = "middle"
    } else {
        markLineData = [
            [
                circleCenter,
                {
                    x: centerX,
                    y: 0
                }
            ]
        ]
    }
    return {markLineData, labelPosition}
}

